class Solution {
public:
    int halveArray(vector<int>& nums) {
        double sum = 0;
        int ret = 0;
        priority_queue<double> pq;
        for(int &x : nums)
        {
            pq.push(x);
            sum += x;
        }
        double tmp = sum;        
        sum /= 2.0;

        while(tmp > sum)
        {
            double x = pq.top();
            tmp -= x;
            tmp += x / 2.0;
            pq.pop();
            pq.push(x / 2.0);
            ret++;
        }

        return ret;
    }
};